var SetHalfMaterialtype = function () {
  var template = /*html*/ `
    <div class="material-config-setting" v-loading.fullscreen.lock="loading">
      <div>
        <el-form :inline="true" size="medium">
          <el-form-item>
            <el-button type="primary" @click="addDialogVisible=true">添加半架物料</el-button>
          </el-form-item>
          <el-form-item label="半成品名称">
            <el-select filterable style="width:200px" v-model="search.nameId" placeholder="请选择半成品名称">
              <el-option value="" label="全部"></el-option>
              <el-option v-for="halfMaterialName in halfMaterialNameList" :key="halfMaterialName.id" :label="halfMaterialName.halfMaterialName"
                :value="halfMaterialName.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="物料类型">
            <el-select filterable style="width:200px" v-model="search.materialType" placeholder="请选择物料类型">
              <el-option value="" label="全部"></el-option>
              <el-option v-for="materialType in materialTypeList" :key="materialType" :label="materialType" :value="materialType"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="报工是否显示">
            <el-select v-model="search.isShow" placeholder="请选择是都显示">
              <el-option label="全部" :value="0"></el-option>
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="setHalfMaterialTypeList(true)">查询</el-button>
          </el-form-item>
        </el-form>
      </div>

      <div class="material-config-table-div">
        <el-table fit stripe border ref="feedOrderTable" :data="halfMaterialTypeList" style="width:100%;" height="parent">
          <el-table-column :resizable="false" prop="halfMaterialName" label="半架组合名称" min-width="70px" header-align="center"></el-table-column>
          <el-table-column :resizable="false" prop="materialType" label="物料类型" min-width="70px" header-align="center"></el-table-column>
          <el-table-column :resizable="false" label="报工是否显示" :auto-width="true" min-width="70px">
            <template slot-scope="scope">
              <span v-if="scope.row.isShow==1">是</span>
              <span v-if="scope.row.isShow==2">否</span>
            </template>
          </el-table-column>
          <el-table-column :resizable="false" prop="createUser" label="创建人" min-width="70px" header-align="center"></el-table-column>
          <el-table-column :resizable="false" prop="createTime" label="创建时间" min-width="70px" header-align="center"></el-table-column>
          <el-table-column :resizable="false" label="操作" fixed="right" min-width="50px" max-width='50px' header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="mini" @click="updateDialog(scope.row)">修改</el-button>
              <el-button type="danger" size="mini" @click="deleteMaterialType(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div style="margin-top:5px;text-align:right" v-if="pagination.totalCount!==0">
        <el-pagination background :page-size="pagination.pageSize" :total="pagination.totalCount" :current-page.sync="pagination.currentPage"
          @current-change="pageChange"></el-pagination>
      </div>

      <!-- 修改弹出框 -->
      <el-dialog title="修改物料属性" :visible.sync="updateDialogVisible">
        <el-form label-width="auto">
          <el-form-item label="半成品名称">
            <span>{{updateParam.halfMaterialName}}</span>
          </el-form-item>
          <el-form-item label="物料类型">
            <span>{{updateParam.materialType}}</span>
          </el-form-item>
          <el-form-item label="状态">
            <el-select v-model="updateParam.isShow" placeholder="请选择状态">
              <el-option label="是" :value="1"></el-option>
              <el-option label="否" :value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="updateDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="updateHalfMaterialType()">确 定</el-button>
        </div>
      </el-dialog>

      <!-- 添加弹出框 -->
      <el-dialog title="添加物料属性" :visible.sync="addDialogVisible">
        <el-form label-width="auto">
          <el-form-item label="半成品名称">
            <el-select style="width:200px" v-model="addParam.nameId" placeholder="请选择半成品名称">
              <el-option value="" label="全部"></el-option>
              <el-option v-for="halfMaterialName in halfMaterialNameList" :key="halfMaterialName.id" :label="halfMaterialName.halfMaterialName"
                :value="halfMaterialName.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="物料类型">
            <el-select filterable style="width:200px" v-model="addParam.materialType" placeholder="请选择物料类型">
              <el-option value="" label="全部"></el-option>
              <el-option v-for="materialType in materialTypeList" :key="materialType" :label="materialType" :value="materialType"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="报工是否显示">
            <el-select style="width:200px" v-model="addParam.isShow">
              <el-option :value="1" label="显示"></el-option>
              <el-option :value="2" label="不显示"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="addDialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addCompanyHalfMaterialType()">确 定</el-button>
        </div>
      </el-dialog>
    </div>
  `;

  return {
    data: function () {
      var search = {
        nameId: '',
        isShow: '',
        materialType: ''
      };
      return {
        loading: false,
        updateDialogVisible: false,
        addDialogVisible: false,
        halfMaterialNameList: [],
        search: _.cloneDeep(search),
        oldSearch: _.cloneDeep(search),
        halfMaterialTypeList: [],
        materialTypeList: [],
        pagination: {
          currentPage: 1,
          totalCount: 0,
          pageSize: 15
        },
        addParam: {
          nameId: '',
          materialType: '',
          isShow: 1
        },
        updateParam: {},
        halfMaterialName: ''
      };
    },
    created: function () {
      var self = this;
      this.loading = true;
      SysUtil.getUser().then(function (user) {
        self.loading = false;
        self.setHalfMaterialName();
        self.setMaterialTypeList();
        self.setHalfMaterialTypeList(true);
      })
    },
    methods: {
      deleteMaterialType: function (row) {
        var self = this;
        this.loading = true;
        ajaxRequest("structureTree/deleteHalfMaterialType", {
          id: row.id
        }, true).then(function (res) {
          self.loading = false;
          self.$alert(res, '信息', {
            callback: function () {
              self.setHalfMaterialTypeList(false);
            }
          });
        }).catch(function () {
          self.loading = false;
        });
      },
      setMaterialTypeList: function () {
        var self = this;
        this.loading = true;
        ajaxRequest("basicData/getRowMaterialType", null, true).then(function (res) {
          self.materialTypeList = res;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },
      setHalfMaterialName: function () {
        var self = this;
        this.loading = true;
        ajaxRequest("structureTree/getHalfMaterialNameList", null, true).then(function (res) {
          self.halfMaterialNameList = res;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },
      addCompanyHalfMaterialType: function () {
        var self = this;
        var postData = self.addParam;
        if (postData.nameId == '') {
          self.$alert('请选择半成品名称', '提示', {});
          return false;
        }
        if (postData.materialType == '') {
          self.$alert('请选择物料类型', '提示', {});
          return false;
        }
        this.loading = true;
        ajaxRequest("structureTree/addHalfMaterialType", postData, true).then(function (res) {
          self.loading = false;
          self.$alert(res, '信息', {
            callback: function () {
              self.setHalfMaterialTypeList();
            }
          });
        }).catch(function () {
          self.loading = false;
        });
        self.addDialogVisible = false;
      },
      updateHalfMaterialType: function () {
        var self = this;
        var postData = self.updateParam;
        this.loading = true;
        ajaxRequest("structureTree/updateHalfMaterialType", postData, true).then(function (res) {
          self.loading = false;
          self.$alert(res, '信息', {
            callback: function () {
              self.setHalfMaterialTypeList(false);
            }
          });
        }).catch(function () {
          self.loading = false;
        });
        self.updateDialogVisible = false;
      },
      updateDialog: function (row) {
        this.updateDialogVisible = true;
        this.updateParam = row;
      },
      setHalfMaterialTypeList: function (isSearch) {
        if (!isSearch) {
          this.search = _.cloneDeep(this.oldSearch);
        }

        var pagination = this.pagination;
        var pageSize = pagination.pageSize;
        var start = (pagination.currentPage - 1) * pageSize;
        var search = this.search;
        search.start = start;
        search.length = pageSize;
        var self = this;
        this.loading = true;
        ajaxRequest("structureTree/getHalfMaterialType", search, true).then(function (res) {
          self.halfMaterialTypeList = res.returnData;
          self.pagination.totalCount = res.iTotalRecords;
          self.loading = false;
        }).catch(function () {
          self.loading = false;
        });
      },
      pageChange: function () {
        this.setHalfMaterialTypeList(false);
      }
    },
    template: template
  };
}();